﻿using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;

namespace SimpleWebApp.Demo02
{
    public abstract class BaseStringContentMiddleware
    {
        private readonly RequestDelegate _next;
        private readonly string _preContent;
        private readonly string _postContent;

        public BaseStringContentMiddleware(RequestDelegate next, string preContent, string postContent)
        {
            _next = next;
            _preContent = preContent;
            _postContent = postContent;
        }

        public async Task InvokeAsync(HttpContext context)
        {
            await context.Response.WriteAsync(_preContent);
            await _next(context);
            await context.Response.WriteAsync(_postContent);
        }
    }
}
